#include "UserRegionBaseWidget.h"
#include "globalObject.h"
#include "UserRegion\UserRegionManager.h"

UserRegionBaseWidget::UserRegionBaseWidget(bool isNew, int regionType, QWidget* parent)
    :QDialog(parent),
    isNewRegion(isNew)
    , userRegionWidgetType(regionType)
{
    UserRegionManager* URM = globalObj::instance().getUserRegionManager();
    connect(this, SIGNAL(UserRegionSettingStart(int)), URM, SLOT(onUserRegionSettingStart(int)));
    connect(this, SIGNAL(UserRegionSettingEnd()), URM, SLOT(onUserRegionSettingEnd()));

    QFile qss(":/UserRegion/UserRegion.qss");
    qss.open(QFile::ReadOnly);
    setStyleSheet(qss.readAll());
    qss.close();
}
UserRegionBaseWidget::~UserRegionBaseWidget()
{

}

void UserRegionBaseWidget::showEvent(QShowEvent *event)
{
    if (isNewRegion)
        emit UserRegionSettingStart(userRegionWidgetType);
    else
        emit UserRegionSettingStart(-1);
    return QDialog::showEvent(event);
}

void UserRegionBaseWidget::closeEvent(QCloseEvent *event)
{
    emit UserRegionSettingEnd();
    return QDialog::closeEvent(event);
}